package com.java.jyy.dao;

import java.util.HashSet;
import java.util.Set;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.java.common.pojo.Dept;
import com.java.common.pojo.Emp;

public class TestDao extends HibernateDaoSupport{
	public boolean test(String id, String pwd){
		System.out.println("TestDao.test("+id+","+pwd+")");
		boolean b = false;
		HibernateTemplate htemp = this.getHibernateTemplate();
		Emp emp = htemp.get(Emp.class, id);
		if(pwd!=null && emp!=null 
				&& pwd.equals(emp.getPassword())){
			b = true;
		}
		return b;
	}
	public Dept getDept(String id){
		System.out.println("TestDao.getDept("+id+")");
		HibernateTemplate htemp = this.getHibernateTemplate();
		Emp emp = htemp.get(Emp.class, id);
		Dept dept = null;
		if(emp!=null){
			dept = emp.getDept();
		}
		return dept;
	}
	public Set<Emp> getEmps(String id){
		System.out.println("TestDao.getEmps("+id+")");
		HibernateTemplate htemp = this.getHibernateTemplate();
		Emp emp = htemp.get(Emp.class, id);
		if(emp!=null){
			Dept dept = emp.getDept();
			if(dept!=null){
				return dept.getEmps();
			} else {
				return new HashSet<Emp>(0);
			}
		} else {
			return new HashSet<Emp>(0);
		}
	}
}
